From 0b714835e5163f2afc182b47e4879eeb799a4039 Mon Sep 17 00:00:00 2001 From: "kaf24@scramble.cl.cam.ac.uk" Date: Fri, 6 Feb 2004 10:32:43 +0000 Subject: [PATCH] bitkeeper revision 1.707.1.1 (40236d4bloPtGchO2u7j218_T6JELQ) pdb.h, xen_serial.c, dom0_ops.c, debug.c, debug-linux.c, traps.c, pdb-stub.c: PDB cleanups. .del-debug-linux.h~21e36ff87b1d6fc7: Delete: xen/common/debug-linux.h --- .rootkeys | 1 - xen/arch/i386/pdb-stub.c | 695 ++++++++++++++++------------------ xen/arch/i386/traps.c | 63 ++- xen/common/debug-linux.c | 45 ++- xen/common/debug-linux.h | 45 --- xen/common/debug.c | 18 +- xen/common/dom0_ops.c | 2 +- xen/drivers/char/xen_serial.c | 9 +- xen/include/asm-i386/pdb.h | 14 +- 9 files changed, 423 insertions(+), 469 deletions(-) delete mode 100644 xen/common/debug-linux.h diff --git a/.rootkeys b/.rootkeys index 5f9d42c286..39b21219d8 100644 --- a/.rootkeys +++ b/.rootkeys @@ -126,7 +126,6 @@ 3ddb79bdrqnW93GR9gZk1OJe1qK-iQ xen/common/brlock.c 3fb10d07GscSWPKxBqpvNfU-dYfa0g xen/common/console.c 4022a73c_BbDFd2YJ_NQYVvKX5Oz7w xen/common/debug-linux.c -4022a73c_KPZ1VEbYOrpAhQffd01kA xen/common/debug-linux.h 3fa152581E5KhrAtqZef2Sr5NKTz4w xen/common/debug.c 3ddb79bdLX_P6iB7ILiblRLWvebapg xen/common/dom0_ops.c 3e6377e4i0c9GtKN65e99OtRbw3AZw xen/common/dom_mem_ops.c diff --git a/xen/arch/i386/pdb-stub.c b/xen/arch/i386/pdb-stub.c index 7734f2f649..9ec8148750 100644 --- a/xen/arch/i386/pdb-stub.c +++ b/xen/arch/i386/pdb-stub.c @@ -5,20 +5,13 @@ #include #include -#undef DEBUG_TRACE -#ifdef DEBUG_TRACE -#define TRC(_x) _x -#else -#define TRC(_x) -#endif - #define BUFMAX 400 #define PDB_DOMAIN_OFFSET 2 /* all domains are positive numbers */ static const char hexchars[]="0123456789abcdef"; -int remote_debug; +static int remote_debug; int pdb_foobar = 0x123456; /* testing */ char *pdb_foobaz = "cambridge"; /* testing */ @@ -31,14 +24,9 @@ static int pdb_in_buffer_ptr; static unsigned char pdb_in_checksum; static unsigned char pdb_xmit_checksum; -int pdb_ctrl_thread = -1; -int pdb_info_thread = -1; -int pdb_stepping = 0; - -int hex (char); -char *mem2hex (char *, char *, int); -char *hex2mem (char *, char *, int); -int hexToInt (char **ptr, int *intValue); +static int pdb_ctrl_thread = -1; +static int pdb_info_thread = -1; +static int pdb_stepping = 0; void pdb_put_packet (unsigned char *buffer, int ack); void pdb_put_char (u_char c); @@ -47,7 +35,7 @@ u_char pdb_get_char (); static volatile int mem_err = 0; void set_mem_err (void) /* NOT USED YET... */ { - mem_err = 1; + mem_err = 1; } /* These are separate functions so that they are so short and sweet @@ -89,8 +77,8 @@ pdb_process_query (char *ptr) if (count > 0) pdb_out_buffer[buf_idx++] = ','; /* - if (domain < 0) - { pdb_out_buffer[buf_idx++] = '-'; domain = domain * -1; } + if (domain < 0) + { pdb_out_buffer[buf_idx++] = '-'; domain = domain * -1; } */ if (domain > 15) { @@ -115,7 +103,7 @@ pdb_process_query (char *ptr) ptr += 16; if (hexToInt (&ptr, &thread)) { - mem2hex ((char *)message, pdb_out_buffer, strlen(message) + 1); + mem2hex ((char *)message, pdb_out_buffer, strlen(message) + 1); } } else if (strcmp(ptr, "Offsets") == 0) @@ -141,223 +129,222 @@ pdb_process_command (char *ptr, struct pt_regs *regs) int ack = 1; /* wait for ack in pdb_put_packet */ int go = 0; - TRC(printk("pdb: [%s]\n", ptr)); - { - pdb_out_buffer[0] = 0; + DPRINTK("pdb: [%s]\n", ptr); - switch (*ptr++) - { - case '?': - pdb_out_buffer[0] = 'S'; - pdb_out_buffer[1] = hexchars[sigval >> 4]; - pdb_out_buffer[2] = hexchars[sigval % 16]; - pdb_out_buffer[3] = 0; - break; - case 'S': /* step with signal */ - case 's': /* step */ - regs->eflags |= 0x100; - pdb_stepping = 1; - return 1; - /* not reached */ - case 'C': /* continue with signal */ - case 'c': /* continue */ - regs->eflags &= ~0x100; - /* jump out before replying to gdb */ - return 1; - /* not reached */ - case 'd': - remote_debug = !(remote_debug); /* toggle debug flag */ - break; - case 'D': /* detach */ - return go; - /* not reached */ - case 'g': /* return the value of the CPU registers */ - { - int idx = 0; - mem2hex ((char *)®s->eax, &pdb_out_buffer[idx], sizeof(regs->eax)); - idx += sizeof(regs->eax) * 2; - mem2hex ((char *)®s->ecx, &pdb_out_buffer[idx], sizeof(regs->ecx)); - idx += sizeof(regs->ecx) * 2; - mem2hex ((char *)®s->edx, &pdb_out_buffer[idx], sizeof(regs->edx)); - idx += sizeof(regs->edx) * 2; - mem2hex ((char *)®s->ebx, &pdb_out_buffer[idx], sizeof(regs->ebx)); - idx += sizeof(regs->ebx) * 2; - mem2hex ((char *)®s->esp, &pdb_out_buffer[idx], sizeof(regs->esp)); - idx += sizeof(regs->esp) * 2; - mem2hex ((char *)®s->ebp, &pdb_out_buffer[idx], sizeof(regs->ebp)); - idx += sizeof(regs->ebp) * 2; - mem2hex ((char *)®s->esi, &pdb_out_buffer[idx], sizeof(regs->esi)); - idx += sizeof(regs->esi) * 2; - mem2hex ((char *)®s->edi, &pdb_out_buffer[idx], sizeof(regs->edi)); - idx += sizeof(regs->edi) * 2; - mem2hex ((char *)®s->eip, &pdb_out_buffer[idx], sizeof(regs->eip)); - idx += sizeof(regs->eip) * 2; - mem2hex ((char *)®s->eflags, &pdb_out_buffer[idx], sizeof(regs->eflags)); - idx += sizeof(regs->eflags) * 2; - mem2hex ((char *)®s->xcs, &pdb_out_buffer[idx], sizeof(regs->xcs)); - idx += sizeof(regs->xcs) * 2; - mem2hex ((char *)®s->xss, &pdb_out_buffer[idx], sizeof(regs->xss)); - idx += sizeof(regs->xss) * 2; - mem2hex ((char *)®s->xds, &pdb_out_buffer[idx], sizeof(regs->xds)); - idx += sizeof(regs->xds) * 2; - mem2hex ((char *)®s->xes, &pdb_out_buffer[idx], sizeof(regs->xes)); - idx += sizeof(regs->xes) * 2; - mem2hex ((char *)®s->xfs, &pdb_out_buffer[idx], sizeof(regs->xfs)); - idx += sizeof(regs->xfs) * 2; - mem2hex ((char *)®s->xgs, &pdb_out_buffer[idx], sizeof(regs->xgs)); + pdb_out_buffer[0] = 0; - /* - TRC(printk (" reg: %s \n", pdb_out_buffer)); - TRC(printk (" ebx: 0x%08lx\n", regs->ebx)); - TRC(printk (" ecx: 0x%08lx\n", regs->ecx)); - TRC(printk (" edx: 0x%08lx\n", regs->edx)); - TRC(printk (" esi: 0x%08lx\n", regs->esi)); - TRC(printk (" edi: 0x%08lx\n", regs->edi)); - TRC(printk (" ebp: 0x%08lx\n", regs->ebp)); - TRC(printk (" eax: 0x%08lx\n", regs->eax)); - TRC(printk (" xds: 0x%08x\n", regs->xds)); - TRC(printk (" xes: 0x%08x\n", regs->xes)); - TRC(printk (" xfs: 0x%08x\n", regs->xfs)); - TRC(printk (" xgs: 0x%08x\n", regs->xgs)); - TRC(printk (" eip: 0x%08lx\n", regs->eip)); - TRC(printk (" xcs: 0x%08x\n", regs->xcs)); - TRC(printk (" efl: 0x%08lx\n", regs->eflags)); - TRC(printk (" esp: 0x%08lx\n", regs->esp)); - TRC(printk (" xss: 0x%08x\n", regs->xss)); - */ + switch (*ptr++) + { + case '?': + pdb_out_buffer[0] = 'S'; + pdb_out_buffer[1] = hexchars[sigval >> 4]; + pdb_out_buffer[2] = hexchars[sigval % 16]; + pdb_out_buffer[3] = 0; + break; + case 'S': /* step with signal */ + case 's': /* step */ + regs->eflags |= 0x100; + pdb_stepping = 1; + return 1; + /* not reached */ + case 'C': /* continue with signal */ + case 'c': /* continue */ + regs->eflags &= ~0x100; + /* jump out before replying to gdb */ + return 1; + /* not reached */ + case 'd': + remote_debug = !(remote_debug); /* toggle debug flag */ + break; + case 'D': /* detach */ + return go; + /* not reached */ + case 'g': /* return the value of the CPU registers */ + { + int idx = 0; + mem2hex ((char *)®s->eax, &pdb_out_buffer[idx], sizeof(regs->eax)); + idx += sizeof(regs->eax) * 2; + mem2hex ((char *)®s->ecx, &pdb_out_buffer[idx], sizeof(regs->ecx)); + idx += sizeof(regs->ecx) * 2; + mem2hex ((char *)®s->edx, &pdb_out_buffer[idx], sizeof(regs->edx)); + idx += sizeof(regs->edx) * 2; + mem2hex ((char *)®s->ebx, &pdb_out_buffer[idx], sizeof(regs->ebx)); + idx += sizeof(regs->ebx) * 2; + mem2hex ((char *)®s->esp, &pdb_out_buffer[idx], sizeof(regs->esp)); + idx += sizeof(regs->esp) * 2; + mem2hex ((char *)®s->ebp, &pdb_out_buffer[idx], sizeof(regs->ebp)); + idx += sizeof(regs->ebp) * 2; + mem2hex ((char *)®s->esi, &pdb_out_buffer[idx], sizeof(regs->esi)); + idx += sizeof(regs->esi) * 2; + mem2hex ((char *)®s->edi, &pdb_out_buffer[idx], sizeof(regs->edi)); + idx += sizeof(regs->edi) * 2; + mem2hex ((char *)®s->eip, &pdb_out_buffer[idx], sizeof(regs->eip)); + idx += sizeof(regs->eip) * 2; + mem2hex ((char *)®s->eflags, &pdb_out_buffer[idx], sizeof(regs->eflags)); + idx += sizeof(regs->eflags) * 2; + mem2hex ((char *)®s->xcs, &pdb_out_buffer[idx], sizeof(regs->xcs)); + idx += sizeof(regs->xcs) * 2; + mem2hex ((char *)®s->xss, &pdb_out_buffer[idx], sizeof(regs->xss)); + idx += sizeof(regs->xss) * 2; + mem2hex ((char *)®s->xds, &pdb_out_buffer[idx], sizeof(regs->xds)); + idx += sizeof(regs->xds) * 2; + mem2hex ((char *)®s->xes, &pdb_out_buffer[idx], sizeof(regs->xes)); + idx += sizeof(regs->xes) * 2; + mem2hex ((char *)®s->xfs, &pdb_out_buffer[idx], sizeof(regs->xfs)); + idx += sizeof(regs->xfs) * 2; + mem2hex ((char *)®s->xgs, &pdb_out_buffer[idx], sizeof(regs->xgs)); + + /* + TRC(printk (" reg: %s \n", pdb_out_buffer)); + TRC(printk (" ebx: 0x%08lx\n", regs->ebx)); + TRC(printk (" ecx: 0x%08lx\n", regs->ecx)); + TRC(printk (" edx: 0x%08lx\n", regs->edx)); + TRC(printk (" esi: 0x%08lx\n", regs->esi)); + TRC(printk (" edi: 0x%08lx\n", regs->edi)); + TRC(printk (" ebp: 0x%08lx\n", regs->ebp)); + TRC(printk (" eax: 0x%08lx\n", regs->eax)); + TRC(printk (" xds: 0x%08x\n", regs->xds)); + TRC(printk (" xes: 0x%08x\n", regs->xes)); + TRC(printk (" xfs: 0x%08x\n", regs->xfs)); + TRC(printk (" xgs: 0x%08x\n", regs->xgs)); + TRC(printk (" eip: 0x%08lx\n", regs->eip)); + TRC(printk (" xcs: 0x%08x\n", regs->xcs)); + TRC(printk (" efl: 0x%08lx\n", regs->eflags)); + TRC(printk (" esp: 0x%08lx\n", regs->esp)); + TRC(printk (" xss: 0x%08x\n", regs->xss)); + */ - break; - } - case 'G': /* set the value of the CPU registers - return OK */ - break; + break; + } + case 'G': /* set the value of the CPU registers - return OK */ + break; - case 'H': - { - int thread; - char *next = &ptr[1]; - if (hexToInt (&next, &thread)) - { - if (thread > 0) - { - thread = thread - PDB_DOMAIN_OFFSET; - } - if (*ptr == 'c') - { - pdb_ctrl_thread = thread; - } - else if (*ptr == 'g') - { - pdb_info_thread = thread; - } - else - { - printk ("ack, unknown command %c (thread: %d)\n", - *ptr, thread); - } - } - strcpy (pdb_out_buffer, "OK"); - break; - } - case 'k': /* kill request */ - { - strcpy (pdb_out_buffer, "OK"); /* ack for fun */ - printk ("don't kill bill...\n"); - ack = 0; - break; - } + case 'H': + { + int thread; + char *next = &ptr[1]; + if (hexToInt (&next, &thread)) + { + if (thread > 0) + { + thread = thread - PDB_DOMAIN_OFFSET; + } + if (*ptr == 'c') + { + pdb_ctrl_thread = thread; + } + else if (*ptr == 'g') + { + pdb_info_thread = thread; + } + else + { + printk ("ack, unknown command %c (thread: %d)\n", + *ptr, thread); + } + } + strcpy (pdb_out_buffer, "OK"); + break; + } + case 'k': /* kill request */ + { + strcpy (pdb_out_buffer, "OK"); /* ack for fun */ + printk ("don't kill bill...\n"); + ack = 0; + break; + } - case 'q': - { - pdb_process_query(ptr); - break; - } + case 'q': + { + pdb_process_query(ptr); + break; + } - /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ - case 'm': - { - /* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */ - if (hexToInt (&ptr, (int *)&addr)) - if (*(ptr++) == ',') - if (hexToInt (&ptr, &length)) - { - ptr = 0; - mem_err = 0; - - if (pdb_info_thread >= 0) - { - pdb_get_values(pdb_info_thread, pdb_buffer, addr, length); - mem2hex (pdb_buffer, pdb_out_buffer, length); - } - else - mem2hex ((char *) addr, pdb_out_buffer, length); - if (mem_err) - { - strcpy (pdb_out_buffer, "E03"); - } - } + /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ + case 'm': + { + /* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */ + if (hexToInt (&ptr, (int *)&addr)) + if (*(ptr++) == ',') + if (hexToInt (&ptr, &length)) + { + ptr = 0; + mem_err = 0; + + if (pdb_info_thread >= 0) + { + pdb_get_values(pdb_info_thread, pdb_buffer, addr, length); + mem2hex (pdb_buffer, pdb_out_buffer, length); + } + else + mem2hex ((char *) addr, pdb_out_buffer, length); + if (mem_err) + { + strcpy (pdb_out_buffer, "E03"); + } + } - if (ptr) - { - strcpy (pdb_out_buffer, "E01"); - } - break; - } - - /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ - case 'M': - { - /* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */ - if (hexToInt (&ptr, (int *)&addr)) - if (*(ptr++) == ',') - if (hexToInt (&ptr, &length)) - if (*(ptr++) == ':') - { - mem_err = 0; - - pdb_set_values(pdb_info_thread, - ptr, addr, length); - - if (mem_err) - { - strcpy (pdb_out_buffer, "E03"); - } - else - { - strcpy (pdb_out_buffer, "OK"); - } - - ptr = 0; - } - if (ptr) - { - strcpy (pdb_out_buffer, "E02"); - } - break; - } - case 'T': - { - int thread; - if (hexToInt (&ptr, &thread)) - { - thread -= PDB_DOMAIN_OFFSET; - struct task_struct *p = find_domain_by_id(thread); - if (p == NULL) - { - strcpy (pdb_out_buffer, "E00"); - } - else - { - strcpy (pdb_out_buffer, "OK"); - } - put_task_struct(p); - } - break; - } - } /* switch */ + if (ptr) + { + strcpy (pdb_out_buffer, "E01"); + } + break; + } - /* reply to the request */ - pdb_put_packet (pdb_out_buffer, ack); + /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ + case 'M': + { + /* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */ + if (hexToInt (&ptr, (int *)&addr)) + if (*(ptr++) == ',') + if (hexToInt (&ptr, &length)) + if (*(ptr++) == ':') + { + mem_err = 0; + + pdb_set_values(pdb_info_thread, + ptr, addr, length); + + if (mem_err) + { + strcpy (pdb_out_buffer, "E03"); + } + else + { + strcpy (pdb_out_buffer, "OK"); + } + + ptr = 0; + } + if (ptr) + { + strcpy (pdb_out_buffer, "E02"); + } + break; } + case 'T': + { + int thread; + if (hexToInt (&ptr, &thread)) + { + thread -= PDB_DOMAIN_OFFSET; + struct task_struct *p = find_domain_by_id(thread); + if (p == NULL) + { + strcpy (pdb_out_buffer, "E00"); + } + else + { + strcpy (pdb_out_buffer, "OK"); + } + put_task_struct(p); + } + break; + } + } /* switch */ + + /* reply to the request */ + pdb_put_packet (pdb_out_buffer, ack); return go; } @@ -439,87 +426,87 @@ int pdb_serial_input(u_char c, struct pt_regs *regs) int hex(char ch) { - if ((ch >= 'a') && (ch <= 'f')) return (ch-'a'+10); - if ((ch >= '0') && (ch <= '9')) return (ch-'0'); - if ((ch >= 'A') && (ch <= 'F')) return (ch-'A'+10); - return (-1); + if ((ch >= 'a') && (ch <= 'f')) return (ch-'a'+10); + if ((ch >= '0') && (ch <= '9')) return (ch-'0'); + if ((ch >= 'A') && (ch <= 'F')) return (ch-'A'+10); + return (-1); } /* convert the memory pointed to by mem into hex, placing result in buf */ /* return a pointer to the last char put in buf (null) */ char * mem2hex (mem, buf, count) - char *mem; - char *buf; - int count; + char *mem; + char *buf; + int count; { - int i; - unsigned char ch; + int i; + unsigned char ch; - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { - ch = get_char (mem++); - *buf++ = hexchars[ch >> 4]; - *buf++ = hexchars[ch % 16]; + ch = get_char (mem++); + *buf++ = hexchars[ch >> 4]; + *buf++ = hexchars[ch % 16]; } - *buf = 0; - return (buf); + *buf = 0; + return (buf); } /* convert the hex array pointed to by buf into binary to be placed in mem */ /* return a pointer to the character AFTER the last byte written */ char * hex2mem (buf, mem, count) - char *buf; - char *mem; - int count; + char *buf; + char *mem; + int count; { - int i; - unsigned char ch; + int i; + unsigned char ch; - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { - ch = hex (*buf++) << 4; - ch = ch + hex (*buf++); - set_char (mem++, ch); + ch = hex (*buf++) << 4; + ch = ch + hex (*buf++); + set_char (mem++, ch); } - return (mem); + return (mem); } int hexToInt (char **ptr, int *intValue) { - int numChars = 0; - int hexValue; - int negative = 0; - - *intValue = 0; - - if (**ptr == '-') - { - negative = 1; - numChars++; - (*ptr)++; - } - while (**ptr) - { - hexValue = hex (**ptr); - if (hexValue >= 0) - { - *intValue = (*intValue << 4) | hexValue; - numChars++; - } - else - break; + int numChars = 0; + int hexValue; + int negative = 0; - (*ptr)++; - } - if (negative) - { - *intValue *= -1; - } + *intValue = 0; + + if (**ptr == '-') + { + negative = 1; + numChars++; + (*ptr)++; + } + + while (**ptr) + { + hexValue = hex (**ptr); + if (hexValue >= 0) + { + *intValue = (*intValue << 4) | hexValue; + numChars++; + } + else + break; + + (*ptr)++; + } + + if ( negative ) + *intValue *= -1; - return (numChars); + return (numChars); } /***********************************************************************/ @@ -533,79 +520,53 @@ hexToInt (char **ptr, int *intValue) */ struct pdb_breakpoint breakpoints; - void pdb_bkpt_add (unsigned long address) { - struct pdb_breakpoint *bkpt; - - bkpt = kmalloc(sizeof(struct pdb_breakpoint), GFP_KERNEL); - INIT_LIST_HEAD(&bkpt->list); - + struct pdb_breakpoint *bkpt = kmalloc(sizeof(*bkpt), GFP_KERNEL); bkpt->address = address; - list_add(&bkpt->list, &breakpoints.list); - - return; } /* * Check to see of the breakpoint is in the list of known breakpoints - * - * return 1 if it has been set, 0 otherwise + * Return 1 if it has been set, 0 otherwise. */ - struct pdb_breakpoint* pdb_bkpt_search (unsigned long address) { - struct pdb_breakpoint *found = NULL; struct list_head *list_entry; struct pdb_breakpoint *bkpt; list_for_each(list_entry, &breakpoints.list) { bkpt = list_entry(list_entry, struct pdb_breakpoint, list); - - if (bkpt->address == address) - { - found = bkpt; - break; - } + if ( bkpt->address == address ) + return bkpt; } - return found; + return NULL; } /* * Remove a breakpoint to the list of known breakpoints. - * * Return 1 if the element was not found, otherwise 0. */ - -void pdb_bkpt_remove_ptr (struct pdb_breakpoint *bkpt) -{ - struct list_head *list_entry = &bkpt->list; - list_del(list_entry); - kfree(bkpt); -} - int pdb_bkpt_remove (unsigned long address) { struct list_head *list_entry; struct pdb_breakpoint *bkpt; - int found = 1; list_for_each(list_entry, &breakpoints.list) { bkpt = list_entry(list_entry, struct pdb_breakpoint, list); - - if (bkpt->address == address) + if ( bkpt->address == address ) { - pdb_bkpt_remove_ptr (bkpt); - found = 0; - break; + list_del(&bkpt->list); + kfree(bkpt); + return 0; } } - return found; + return 1; } /***********************************************************************/ @@ -617,16 +578,16 @@ int pdb_high_bit = 1; void pdb_put_char (u_char c) { - extern void debug_putchar(u_char); - u_char cc = pdb_high_bit ? c | 0x80 : c; - debug_putchar(cc); + extern void debug_putchar(u_char); + u_char cc = pdb_high_bit ? c | 0x80 : c; + debug_putchar(cc); } u_char pdb_get_char () { - extern u_char debug_getchar(); - u_char cc = debug_getchar(); - return cc & 0x7f; + extern u_char debug_getchar(); + u_char cc = debug_getchar(); + return cc & 0x7f; } /* send the packet in buffer. */ @@ -713,51 +674,57 @@ void pdb_get_packet(char *buffer) /* * process a machine interrupt or exception - * return 1 if pdb is not interested in the exception; it should + * Return 1 if pdb is not interested in the exception; it should * be propagated to the guest os. */ - +#define DEBUG_EXCEPTION 1 +#define BREAKPT_EXCEPTION 3 +#define KEYPRESS_EXCEPTION 136 int pdb_handle_exception(int exceptionVector, struct pt_regs *xen_regs) { int signal = 0; - printk ("pdb_handle_exception [0x%x][0x%lx]\n", - exceptionVector, xen_regs->eip); - - /* if pdb didn't set the breakpoint, and - pdb is not single stepping, and - the user didn't press the magic debug key on the console, - then pass the exception up to the guest os */ - if (pdb_bkpt_search(xen_regs->eip - 1) == NULL && - pdb_stepping == 0 && - exceptionVector != 0x88) + /* + * If PDB didn't set the breakpoint, is not single stepping, and the user + * didn't press the magic debug key, then we don't handle the exception. + */ + if ( (pdb_bkpt_search(xen_regs->eip - 1) == NULL) && + !pdb_stepping && (exceptionVector != KEYPRESS_EXCEPTION) ) { - TRC(printk("pdb: external breakpoint at 0x%lx\n", xen_regs->eip)); + DPRINTK("pdb: external breakpoint at 0x%lx\n", xen_regs->eip); return 1; } - if (pdb_stepping == 1) + printk("pdb_handle_exception [0x%x][0x%lx]\n", + exceptionVector, xen_regs->eip); + + if ( pdb_stepping ) { + /* Stepped one instruction; now return to normal execution. */ xen_regs->eflags &= ~0x100; pdb_stepping = 0; } - if (exceptionVector == 0x03) + if ( exceptionVector == BREAKPT_EXCEPTION ) { - xen_regs->eip --; + /* Executed Int3: replace breakpoint byte with real program byte. */ + xen_regs->eip--; } - /* generate a signal for gdb */ - switch (exceptionVector) + /* Generate a signal for GDB. */ + switch ( exceptionVector ) { - case 136 : signal = 2; break; /* SIGINT */ - case 1 : signal = 5; break; /* SIGTRAP */ - case 3 : signal = 5; break; /* SIGTRAP */ - default : - printk ("can't generate signal for unknown exception vector %d\n", - exceptionVector); - break; + case KEYPRESS_EXCEPTION: + signal = 2; break; /* SIGINT */ + case DEBUG_EXCEPTION: + signal = 5; break; /* SIGTRAP */ + case BREAKPT_EXCEPTION: + signal = 5; break; /* SIGTRAP */ + default: + printk("can't generate signal for unknown exception vector %d\n", + exceptionVector); + break; } pdb_out_buffer[0] = 'S'; @@ -766,15 +733,11 @@ int pdb_handle_exception(int exceptionVector, pdb_out_buffer[3] = 0; pdb_put_packet(pdb_out_buffer, 1); - while (1) - { + do { pdb_out_buffer[0] = 0; pdb_get_packet(pdb_in_buffer); - if (pdb_process_command(pdb_in_buffer, xen_regs)) - { - return 0; - } } + while ( pdb_process_command(pdb_in_buffer, xen_regs) == 0 ); return 0; } @@ -790,7 +753,12 @@ void initialize_pdb() extern char opt_pdb[]; int pdb_com_port; - if (strncmp(opt_pdb, "com", 3) == 0) + /* Certain state must be initialised even when PDB will not be used. */ + breakpoints.address = 0; + INIT_LIST_HEAD(&breakpoints.list); + pdb_stepping = 0; + + if ( strncmp(opt_pdb, "com", 3) == 0 ) { extern void debug_set_com_port(int port); @@ -800,20 +768,13 @@ void initialize_pdb() } else { - if (strcmp(opt_pdb, "none") != 0) - { + if ( strcmp(opt_pdb, "none") != 0 ) printk ("pdb: unknown option\n"); - } return; } - printk ("Initializing pervasive debugger (PDB) [%s] port %d, high %d\n", - opt_pdb, pdb_com_port, pdb_high_bit); - - breakpoints.address = 0; - INIT_LIST_HEAD(&breakpoints.list); - - pdb_stepping = 0; + printk("Initializing pervasive debugger (PDB) [%s] port %d, high %d\n", + opt_pdb, pdb_com_port, pdb_high_bit); /* ack any spurrious gdb packets */ pdb_put_char ('+'); @@ -826,6 +787,6 @@ void initialize_pdb() void breakpoint(void) { - if (pdb_initialized) + if ( pdb_initialized ) asm("int $3"); } diff --git a/xen/arch/i386/traps.c b/xen/arch/i386/traps.c index 4f2cd6af66..13ec1a8e6c 100644 --- a/xen/arch/i386/traps.c +++ b/xen/arch/i386/traps.c @@ -224,30 +224,6 @@ static inline void do_trap(int trapnr, char *str, smp_processor_id(), trapnr, str, error_code); } -static inline void do_int3_exception(int trapnr, - struct pt_regs *regs, - long error_code) -{ - struct task_struct *p = current; - struct guest_trap_bounce *gtb = guest_trap_bounce+smp_processor_id(); - trap_info_t *ti; - - if ((regs->xcs & 3) != 3) - { - pdb_handle_exception(trapnr, regs); - return; - } - - ti = current->thread.traps + trapnr; - gtb->flags = GTBF_TRAP_NOCODE; - gtb->error_code = error_code; - gtb->cs = ti->cs; - gtb->eip = ti->address; - if ( TI_GET_IF(ti) ) - clear_bit(EVENTS_MASTER_ENABLE_BIT, &p->shared_info->events_mask); - return; -} - #define DO_ERROR_NOCODE(trapnr, str, name) \ asmlinkage void do_##name(struct pt_regs * regs, long error_code) \ { \ @@ -275,10 +251,34 @@ DO_ERROR(17, "alignment check", alignment_check) DO_ERROR_NOCODE(18, "machine check", machine_check) DO_ERROR_NOCODE(19, "simd error", simd_coprocessor_error) -asmlinkage void do_int3(struct pt_regs * regs, long error_code) +asmlinkage void do_int3(struct pt_regs *regs, long error_code) { - if (pdb_initialized) do_int3_exception(3, regs, error_code); - else do_trap(3, "int3", regs, error_code, 0); + struct task_struct *p = current; + struct guest_trap_bounce *gtb = guest_trap_bounce+smp_processor_id(); + trap_info_t *ti; + + if ( (regs->xcs & 3) != 3 ) + { + if ( pdb_handle_exception(3, regs) == 0 ) + return; + if ( unlikely((regs->xcs & 3) == 0) ) + { + show_registers(regs); + panic("CPU%d FATAL TRAP: vector = 3 (Int3)\n" + "[error_code=%08x]\n", + smp_processor_id(), error_code); + } + } + + ti = current->thread.traps + 3; + gtb->flags = GTBF_TRAP_NOCODE; + gtb->error_code = error_code; + gtb->cs = ti->cs; + gtb->eip = ti->address; + if ( TI_GET_IF(ti) ) + clear_bit(EVENTS_MASTER_ENABLE_BIT, &p->shared_info->events_mask); + return; + } asmlinkage void do_double_fault(void) @@ -525,11 +525,6 @@ asmlinkage void do_debug(struct pt_regs * regs, long error_code) struct task_struct *tsk = current; struct guest_trap_bounce *gtb = guest_trap_bounce+smp_processor_id(); - /* - printk("do_debug_exceptionn [%lx][%lx][%x]\n", - error_code, regs->eip, regs->xcs); - */ - __asm__ __volatile__("movl %%db6,%0" : "=r" (condition)); if ((condition & (1 << 14)) != (1 << 14)) @@ -538,7 +533,7 @@ asmlinkage void do_debug(struct pt_regs * regs, long error_code) } __asm__("movl %0,%%db6" : : "r" (0)); - if (pdb_handle_exception(1, regs)) /* propagate to domain */ + if ( pdb_handle_exception(1, regs) != 0 ) { tsk->thread.debugreg[6] = condition; @@ -546,8 +541,6 @@ asmlinkage void do_debug(struct pt_regs * regs, long error_code) gtb->cs = tsk->thread.traps[1].cs; gtb->eip = tsk->thread.traps[1].address; } - - return; } diff --git a/xen/common/debug-linux.c b/xen/common/debug-linux.c index 8e4f0c63dc..5c178a4a7d 100644 --- a/xen/common/debug-linux.c +++ b/xen/common/debug-linux.c @@ -2,13 +2,54 @@ #include #include #include - -#include "debug-linux.h" +#include /* * linux specific pdb stuff */ +/* from linux/sched.h */ +#define PIDHASH_SZ (4096 >> 2) +#define pid_hashfn(x) ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1)) + +/* from asm-xeno/pgtable-2level.h */ +#define PGDIR_SHIFT 22 +#define PTRS_PER_PGD 1024 + +/* from asm-xeno/page.h */ +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1UL << PAGE_SHIFT) +#define PAGE_MASK (~(PAGE_SIZE-1)) + +#define __PAGE_OFFSET (0xC0000000) +#define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET) +#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) +#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) + +/* from debug.h */ +#define ENTRIES_PER_L1_PAGETABLE 1024 +#define L1_PAGE_BITS ( (ENTRIES_PER_L1_PAGETABLE - 1) << PAGE_SHIFT ) + + +/* adapted from asm-xeno/page.h */ +static inline unsigned long machine_to_phys(int domain, unsigned long machine) +{ + unsigned long phys; + pdb_get_values(domain, (u_char *) &phys, + (unsigned long) machine_to_phys_mapping + (machine >> PAGE_SHIFT) * 4, + sizeof(phys)); + phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK); + return phys; +} + + +#define pidhash_addr 0xc018f260UL + +#define task_struct_mm_offset 0x2c +#define task_struct_pid_offset 0x7c +#define task_struct_pidhash_next_offset 0xb0 +#define mm_struct_pgd_offset 0x0c + /* static inline struct task_struct *find_task_by_pid(int pid) { diff --git a/xen/common/debug-linux.h b/xen/common/debug-linux.h deleted file mode 100644 index ae93d34b26..0000000000 --- a/xen/common/debug-linux.h +++ /dev/null @@ -1,45 +0,0 @@ -#include - -/* from linux/sched.h */ -#define PIDHASH_SZ (4096 >> 2) -#define pid_hashfn(x) ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1)) - -/* from asm-xeno/pgtable-2level.h */ -#define PGDIR_SHIFT 22 -#define PTRS_PER_PGD 1024 - -/* from asm-xeno/page.h */ -#define PAGE_SHIFT 12 -#define PAGE_SIZE (1UL << PAGE_SHIFT) -#define PAGE_MASK (~(PAGE_SIZE-1)) - -#define __PAGE_OFFSET (0xC0000000) -#define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET) -#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) -#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) - -/* from debug.h */ -#define ENTRIES_PER_L1_PAGETABLE 1024 -#define L1_PAGE_BITS ( (ENTRIES_PER_L1_PAGETABLE - 1) << PAGE_SHIFT ) - - -/* adapted from asm-xeno/page.h */ -static inline unsigned long machine_to_phys(int domain, unsigned long machine) -{ - unsigned long phys; - pdb_get_values(domain, (u_char *) &phys, - (unsigned long) machine_to_phys_mapping + (machine >> PAGE_SHIFT) * 4, - sizeof(phys)); - phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK); - return phys; -} - - -#define pidhash_addr 0xc018f260UL - -#define task_struct_mm_offset 0x2c -#define task_struct_pid_offset 0x7c -#define task_struct_pidhash_next_offset 0xb0 -#define mm_struct_pgd_offset 0x0c - -extern u_char pdb_linux_get_value (int domain, int pid, unsigned long addr); diff --git a/xen/common/debug.c b/xen/common/debug.c index 852b3bca03..3642c4c8d5 100644 --- a/xen/common/debug.c +++ b/xen/common/debug.c @@ -23,8 +23,9 @@ /****************************************************************************/ -int pdb_change_values (int domain, u_char *buffer, unsigned long addr, - int length, int rw); +extern int pdb_change_values (int domain, u_char *buffer, unsigned long addr, + int length, int rw); +extern u_char pdb_linux_get_value (int domain, int pid, unsigned long addr); /* * Set memory in a domain's address space @@ -36,22 +37,19 @@ int pdb_change_values (int domain, u_char *buffer, unsigned long addr, int pdb_set_values (int domain, u_char *buffer, unsigned long addr, int length) { - int count; - void *bkpt; - count = pdb_change_values(domain, buffer, addr, length, 2); + int count = pdb_change_values(domain, buffer, addr, length, 2); /* this is a bit x86 specific at the moment... */ if (length == 1 && buffer[0] == 'c' && buffer[1] == 'c') { /* inserting a new breakpoint */ - pdb_bkpt_add (addr); + pdb_bkpt_add(addr); TRC(printk("pdb breakpoint detected at 0x%lx\n", addr)); } - else if ((bkpt = pdb_bkpt_search(addr))) + else if ( pdb_bkpt_remove(addr) == 0 ) { /* removing a breakpoint */ TRC(printk("pdb breakpoint cleared at 0x%lx\n", addr)); - pdb_bkpt_remove_ptr(bkpt); } return count; @@ -86,8 +84,6 @@ int pdb_change_values (int domain, u_char *buffer, unsigned long addr, u_char *page; int bytes = 0; - extern char *hex2mem (char *, char *, int); - p = find_domain_by_id(domain); if ((addr >> PAGE_SHIFT) == ((addr + length - 1) >> PAGE_SHIFT)) @@ -210,8 +206,6 @@ void pdb_do_debug (dom0_op_t *op) for (loop = 0; loop < op->u.debug.in2; loop++) /* length */ { - extern u_char pdb_linux_get_value (int domain, int pid, unsigned long addr); - if (loop % 8 == 0) { printk ("\n%08x ", op->u.debug.in1 + loop); diff --git a/xen/common/dom0_ops.c b/xen/common/dom0_ops.c index b3aa93ca3b..1d55ade1a5 100644 --- a/xen/common/dom0_ops.c +++ b/xen/common/dom0_ops.c @@ -15,6 +15,7 @@ #include #include #include +#include extern unsigned int alloc_new_dom_mem(struct task_struct *, unsigned int); @@ -427,7 +428,6 @@ long do_dom0_op(dom0_op_t *u_dom0_op) case DOM0_DEBUG: { - extern void pdb_do_debug(dom0_op_t *); pdb_do_debug(op); copy_to_user(u_dom0_op, op, sizeof(*op)); ret = 0; diff --git a/xen/drivers/char/xen_serial.c b/xen/drivers/char/xen_serial.c index 582cccbc75..6dc941b86d 100644 --- a/xen/drivers/char/xen_serial.c +++ b/xen/drivers/char/xen_serial.c @@ -3,6 +3,7 @@ #include #include #include +#include /* Register offsets */ #define NS16550_RBR 0x00 /* receive buffer */ @@ -116,7 +117,8 @@ void serial_putch(u_char c) void serial_putchar(u_char c) { serial_putch(c); - if (c == '\n') serial_putch('\r'); + if ( c == '\n' ) + serial_putch('\r'); } static spinlock_t serial_lock; @@ -129,13 +131,12 @@ static void serial_rx_int(int irq, void *dev_id, struct pt_regs *regs) spin_lock_irqsave(&serial_lock, flags); - while (serial_testchar()) + while ( serial_testchar() ) { c = serial_getchar(); - if (c & 0x80) + if ( c & 0x80 ) { - extern int pdb_serial_input(u_char, struct pt_regs *); pdb_serial_input(c & 0x7f, regs); } else diff --git a/xen/include/asm-i386/pdb.h b/xen/include/asm-i386/pdb.h index 5799328ea1..b1416784fc 100644 --- a/xen/include/asm-i386/pdb.h +++ b/xen/include/asm-i386/pdb.h @@ -19,15 +19,20 @@ extern int pdb_com_port; extern int pdb_high_bit; extern void initialize_pdb(void); + +/* Get/set values from generic debug interface. */ extern int pdb_set_values (int domain, u_char *buffer, unsigned long addr, int length); extern int pdb_get_values (int domain, u_char *buffer, unsigned long addr, int length); +/* External entry points. */ extern int pdb_handle_exception(int exceptionVector, struct pt_regs *xen_regs); +extern int pdb_serial_input(u_char c, struct pt_regs *regs); +extern void pdb_do_debug(dom0_op_t *op); - +/* Breakpoints. */ struct pdb_breakpoint { struct list_head list; @@ -35,7 +40,12 @@ struct pdb_breakpoint }; extern void pdb_bkpt_add (unsigned long address); extern struct pdb_breakpoint* pdb_bkpt_search (unsigned long address); -extern void pdb_bkpt_remove_ptr (struct pdb_breakpoint *bkpt); extern int pdb_bkpt_remove (unsigned long address); +/* Conversions. */ +extern int hex (char); +extern char *mem2hex (char *, char *, int); +extern char *hex2mem (char *, char *, int); +extern int hexToInt (char **ptr, int *intValue); + #endif /* __PDB_H__ */ -- 2.30.2